package com.ruoyi.project.platform.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.project.platform.dto.RRunningMappingDto;
import com.ruoyi.project.platform.dto.UserRunningDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.platform.domain.RRunningMapping;
import com.ruoyi.project.platform.service.IRRunningMappingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 运行机器人参数Controller
 *
 * @author ruoyi
 * @date 2020-07-26
 */
@RestController
@RequestMapping("/platform/mapping")
public class RRunningMappingController extends BaseController {
    @Autowired
    private IRRunningMappingService rRunningMappingService;

    /**
     * 查询运行机器人参数列表
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:list')")
    @GetMapping("/list")
    public TableDataInfo list(RRunningMapping rRunningMapping) {
        startPage();
        List<RRunningMappingDto> list = rRunningMappingService.selectRRunningMappingList(rRunningMapping);
        return getDataTable(list);
    }

    /**
     * 获取运行机器人参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:query')")
    @GetMapping(value = "/{runningId}")
    public AjaxResult getInfo(@PathVariable("runningId") Long runningId) {
        return AjaxResult.success(rRunningMappingService.selectRRunningMappingById(runningId));
    }

    /**
     * 新增运行机器人参数
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:add')")
    @Log(title = "运行机器人参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RRunningMapping rRunningMapping) {
        return toAjax(rRunningMappingService.insertRRunningMapping(rRunningMapping));
    }

    /**
     * 新增运行机器人参数
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:add')")
    @Log(title = "运行机器人参数", businessType = BusinessType.INSERT)
    @PostMapping("saveList")
    public AjaxResult addList(@RequestBody List<RRunningMappingDto> rRunningMapping, @RequestParam Long runningId) {
        return toAjax(rRunningMappingService.saveRRunningMappingList(rRunningMapping,runningId));
    }

    /**
     * 修改运行机器人参数
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:edit')")
    @Log(title = "运行机器人参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RRunningMapping rRunningMapping) {
        return toAjax(rRunningMappingService.updateRRunningMapping(rRunningMapping));
    }

    /**
     * 修改运行机器人参数
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:edit')")
    @Log(title = "运行机器人参数控制", businessType = BusinessType.UPDATE)
    @PutMapping("editOrSaveList")
    public AjaxResult editOrSave(@RequestBody Map<String,String> mappings) {
        return toAjax(rRunningMappingService.updateOrSaveRRunningMapping(mappings));
    }

    /**
     * 删除运行机器人参数
     */
    @PreAuthorize("@ss.hasPermi('platform:mapping:remove')")
    @Log(title = "运行机器人参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{runningIds}")
    public AjaxResult remove(@PathVariable Long[] runningIds) {
        return toAjax(rRunningMappingService.deleteRRunningMappingByIds(runningIds));
    }
}
